<?php
include_once '../Classes/Aluno.php';
$obj = new Aluno();
$array = $obj->listarDevedores();
if ($array) {
    ?>
    <table>
        <tr>
            <th>CPF</th>
            <th>Nome</th>
            <th>Aprovar?</th>
        </tr>
        <?php
        for ($i = 0; $array["CPF"][$i]; $i++) {
            echo "<tr>";
            echo "<td style='border-top: solid black;'>" . $array["CPF"][$i] . "</td>";
            echo "<td style='border-top: solid black;'>" . strtoupper($array["ALUNO"][$i]) . "</td>";
            ?>
        <td style='border-top: solid black;'><div id="<?=$i?>" name="<?=$i?>"><input type="button" onclick="aprovarAluno('<?= $array["CPF"][$i] ?>','<?=$i?>')" value="Pagou"/></div></td>
                <?php
                echo "</tr>";
            }
            ?>
    </table>
    <script type="text/javascript">
        function aprovarAluno(cpf,linha){
            var dataString = 'cpf='+cpf;
            var response = $.ajax({
                type: "POST",
                url:"Controlador/Aprovar.php",
                data: dataString,
                async: false
            }).responseText;
            $(("#"+linha)).html(response);
        }
    </script>
    }
    <?php
}
?>

